Placing a Project in Git Management
Repositories and branches in CODESYS Git
To manage a CODESYS project in Git with the help of CODESYS Git, it is first of all sufficient to use a purely local Git repository in the "project storage" (working directory), also referred to as a "Git repository" in the following text. For the collaboration with other developers on the project, the local Git repository can be linked with a "remote repository" which is accessible to everyone.
Work on the project managed in Git is done first in local branches (work statuses). The local branches can track a remote branch (link to the remote repository). Remote branches are the existing representatives in the local Git repository of the respective branch in the remote repository.
Tip
You can use the Move Repository command to move a Git repository to another location in the file system.
Tip
You can use the Disconnect from Git Repository command to unlink a project from the source code management in Git.
Warning
When encryption is set for the CODESYS project (CODESYS-Project Settings – Security), the Git repository (neither local nor remote) is not automatically protected accordingly.
Using git init
to place a CODESYS project in Git management
Requirement: CODESYS Git is installed. A CODESYS project is open.
Prepare an empty directory in the file system for the Git project repository to contain the local Git repository. Example:
D:\git_local\rep1
In CODESYS Git, open the CODESYS project which should be placed under Git management. Example:
myproj.project
.Click the
command.The Initialize Git Repository dialog opens.
In the dialog, specify the path of the empty directory for the Git project storage (example:
D:\git_local\rep1
). The Git repository created there is your local "master".If there is no global configuration file
.gitconfig
in the local user directory (example:C:\Users\m.muster
), then a dialog prompt will open for you to create a basic configuration for all CODESYS Git actions. You get the same dialog for entering some parameters as via the Git Config command. The default setting for Default Branch ismaster
. Enter your user data Username and Email address (examplem.muster
,m.muster@company.com
).The objects in the project navigator are provided with blue plus signs
(status: "added"), and the root node (project name) is provided with an orange square
(status: "changed").
The path of the Git project storage is displayed in the
view.As a result, the project management in the Git repository located in the project storage is initialized.
Save the project (as usual without Git management) in a separate project directory (example:
D:\git_projects\myproj.project
). Note: The project files are therefore subject to double data management.Open the Git Status view. In Unstaged Changes in the lower part, select the displayed project objects. Then click the
button to stage it for a commit.
The objects are moved above to Staged Changes.
Click the
button (commit). In the Commit staged changes dialog, enter a commit message and click OK to confirm.
The current status of the project objects is committed to the local repository.
Click the
command.In the History view, the first commit for the "master" is shown with more information.
In the project navigator, solid green circle symbols
are displayed in front of the committed objects and in front of the root. This means that the status of the project is in sync with its status in the Git repository.
Click the Local (1) filter.
command and enable theThe default branch for the Git repository is visible as
master
(refs/heads/master)
.In the file system, go to the local repository
D:\git_local\rep1
.Now the directory
.git
(the actual Git repository) is located here with the subdirectoryproject
and the files.gitattributes
,.gitignore
, and.apsession
. The directoryproject
contains the objects of the CODESYS project.Now you can still link the project (when necessary) with a remote repository.
Using Clone Git Repository
to create a new CODESYS project already in Git management
With Git Clone, a new CODESYS project is created, which is version-managed in Git. As a result, cloning a remote repository creates the new project storage (the new working directory with the Git repository).
Requirement: CODESYS Git is installed. You have access to a remote repository.
Open CODESYS Git. Click the command. It is available when no CODESYS project is open.
The Git Clone dialog opens.
In Source URL, specify the URL or file path of the remote repository to be cloned (example:
D:\git_remotes\remote1
).In Git storage path, specify the empty file directory intended for the new Git project storage (new Git repository) (example:
D:\git_local\rep1
).In Project file, specify a project directory where the new CODESYS project should be saved in addition to and outside of Git (!) (example:
D:\git_projects\myproj1.project
, double data management!).In Project file type, select whether it should be a standard project or a library project. Confirm the dialog.
If there is no global configuration file
.gitconfig
in the local user directory (example:C:\Users\m.muster
), then a dialog prompt will open for you to create a basic configuration for all CODESYS Git actions. See the instructions above for initializing a Git project (Step 4).If the Git option Accept self signed certificate is not selected, then CODESYS Git first checks the certificate for the connection to the server from which the project should be cloned. If the certificate is not trusted, then you will be given the option of allowing the connection after a personal check.
The new project is opened. The new working directory is created and automatically initialized as the Git repository. It first has the exact status of the remote repository when the cloning occurred.
In the CODESYS project, click the command.
In the Git Branches view, the remote branches are already visible. By default, for the remote "master" branch, a local "master" branch is also created, which tracks the remote branch. Now you can start working in this local branch immediately. In addition, a link (tracking) of the local branch to the "representative" remote branch (
origin/master
) of the new Git repository is already established.
Linking a project to a remote repository
Requirement: A project is managed in Git in CODESYS Git. Now you want to establish a link to a remote repository to synchronize there your commits with the commits of others.
Click the Git Remotes view, click the
command. In theAdd button.
The Add new Git Remote dialog opens.
Specify the path and a name for the remote repository to be linked. Example: Alias Name:
origin
, URL:D:\git_remote
.Run the
Fetch command and then click the command to switch to the Git Branches view.
Credentials are usually required to access a remote repository. Only if no valid credentials are found on the computer will the Credentials needed dialog for your input. For more information, see: Credentials needed.
Select the Remote (<n>) filter.
You see the remote branches.
Unselect the Remote (<n>) filter. Select the Local (1) filter. Select the
master
entry and click Upstream Set. If there is still no remote branch (origin/master
) for the selected remote repository, then the following happens:The Set Upstream Remote for Branch dialog opens. The remote name
origin
is already predefined.Click OK to confirm the entries.
→ The Tracking and Current options are selected for the
master
. In Tracked Branch, Name,origin/master
is displayed.This means that the remote branch
origin/master
for the remote repository is created internally. This is only used as a representative: No work is done directly on this branch.Select the
master
and click Push. Select the Remote (1) filter.Now the representative branch
origin/master
under Git Branches Remote (1) is also displayed. The link from the localmaster
to the remote repository is established by means of its representativeorigin/master
.In the Git Branches Local (<1>) view, you can now use the Track branch command to link the local branch (
master
) of the Git repository to the new remote branch of the remote repository.